import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
import React, { useLayoutEffect, useState } from "react";
import CircularProgress from "@mui/material/CircularProgress";
import { toParams } from "../utils/oauth";
import { useDispatch, useSelector } from "react-redux";
import kingsInstance from "../instance";
import { EVENT } from "../enums";
import { jsx as _jsx } from "react/jsx-runtime";
function OauthCallback(props) {
    var _useState = _sliced_to_array(useState(location.search.replace(/^\?/, "") && toParams(location.search.replace(/^\?/, ""))), 1), state = _useState[0];
    var theme = useSelector(function(st) {
        return st.app.theme;
    });
    var dispatch = useDispatch();
    var setStore = function() {
        var _ref = _async_to_generator(function() {
            return _ts_generator(this, function(_state) {
                /** 写入本地 */ state && dispatch.app.SET_OAUTH2(state);
                kingsInstance.emit(EVENT.oauth2, state);
                kingsInstance.once(EVENT.connect, function() {
                    var _props_push;
                    return (_props_push = props.push) === null || _props_push === void 0 ? void 0 : _props_push.call(props, "/");
                });
                return [
                    2
                ];
            });
        });
        return function setStore() {
            return _ref.apply(this, arguments);
        };
    }();
    useLayoutEffect(function() {
        setStore();
    }, []);
    /** 显示loading 页面 */ return /*#__PURE__*/ _jsx("div", {
        style: {
            right: 0,
            bottom: 0,
            top: 0,
            left: "0",
            position: "fixed",
            color: theme == "light" ? "var(--primary)" : "#fff"
        },
        children: /*#__PURE__*/ _jsx(CircularProgress, {
            color: "inherit"
        })
    });
}
export default OauthCallback;

 //# sourceMappingURL=oauth-callback.js.map